package com.goodmean.common.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

public class EncodingInterceptor implements Interceptor {

    @Override
    public void intercept(Invocation invocation) {
        HttpServletRequest request = invocation.getController().getRequest();
        HttpServletRequest response = invocation.getController().getRequest();
        try {
            request.setCharacterEncoding("UTF-8");
            invocation.invoke();
            response.setCharacterEncoding("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
}
